<?php
namespace App\Admin\Renderable;

use App\Models\WxIcon;
use App\Wen\Utils\FieldUtils;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class IconRender extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new WxIcon(), function (Grid $grid) {
            global $__MINI_GLOBAL_TENANT_ID__;
            if($__MINI_GLOBAL_TENANT_ID__ > 0){
                $grid->model()->where('tenant_id', '=', $__MINI_GLOBAL_TENANT_ID__);
            }
            $grid->quickSearch(['id','name'])->placeholder('搜索图标ID，名字...');
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('name','名字');
            $grid->column('icon', 'icon')->display(function ($value){
                return '<i class="mini-icon '.$value.'"></i>';
            });
            $grid->column('unicode16');

            $grid->column('img', '图片')->image('',80);
            $grid->column('desc', '描述')->limit(20);;
            $grid->column('type', '类型')->using(FieldUtils::getUrlTypes());
            $grid->column('target_id','跳转id');
            $grid->column('is_admin', '仅管理可见')->using([0=>'否', 1 =>'是']);
//            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
            $grid->disableBatchActions();
            $grid->disableActions();
        });
    }
}
